# _*_ coding: UTF-8 _*_

from django.http import HttpResponseRedirect
from django.shortcuts import render


# Create your views here.
from Activity.models import HotNews,CorpInfo, Case, Service, Client
from GuoWu import settings


def request_page(request, page):
    print (page)
    args = {"corp_info": CorpInfo.objects.last(),
            "bg_image": "../static/img/por_bodybg.gif"}

    if not page:
        return HttpResponseRedirect("/index.html")

    #显示公司首页
    elif page == "index.html":
        args['flash_images'] = args['corp_info'].flash_images.all()
        args['hot_news'] = HotNews.objects.all()
        del args['bg_image']

    #现实案例
    elif page == "case.html":
        id = request.GET.get('id')
        if not id:
            args["cases"] = Case.objects.all()
        else:
            args['case'] = Case.objects.get(id=int(id))

    #显示服务页面
    elif page == "service.html":
        id = request.GET.get('id')
        if id is None:
            args['services'] = Service.objects.all()
        else:
            try:
                args['service'] = Service.objects.get(id=int(id))
            except:
                pass
    #
    # elif page == "client.html":
    #     args['clients'] = Client.objects.all()

    return render(request, '{0}'.format(page), args)

def request_res(request):
    return HttpResponseRedirect("http://"+settings.STATIC_RESOURCE_HOST+request.path)